package cn.com.stary1993.kite.captcha.config;

import cn.com.stary1993.kite.captcha.store.CacheStore;
import cn.com.stary1993.kite.captcha.support.simple.DefaultSimpleImageCaptcha;
import cn.com.stary1993.kite.captcha.support.simple.SimpleImageCaptcha;
import cn.com.stary1993.kite.captcha.support.simple.generator.DefaultSimpleImageCaptchaGenerator;
import cn.com.stary1993.kite.captcha.support.simple.generator.SimpleImageCaptchaGenerator;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration(proxyBeanMethods = false)
@ConditionalOnProperty(prefix = CaptchaProperties.PREFIX + "." + CaptchaProperties.SIMPLE, name = "enabled",
        havingValue = "true")
public class SimpleImageCaptchaAutoConfiguration {

    @Bean
    @ConditionalOnMissingBean
    public SimpleImageCaptcha simpleImageCaptcha(CacheStore cacheStore,
                                                 CaptchaProperties prop,
                                                 SimpleImageCaptchaGenerator simpleImageCaptchaGenerator) {
        return new DefaultSimpleImageCaptcha(cacheStore, prop, simpleImageCaptchaGenerator);
    }

    @Bean
    @ConditionalOnMissingBean
    public SimpleImageCaptchaGenerator simpleImageCaptchaGenerator(CaptchaProperties prop) {
        return new DefaultSimpleImageCaptchaGenerator(prop);
    }
}
